package argo.hot100.tree;

import java.util.LinkedList;
import java.util.Queue;

public class IsSymmetric {


    public boolean isSymmetric(TreeNode root) {
        return judgeQueue(root, root);
    }

    public boolean judgeQueue(TreeNode left, TreeNode right) {

        Queue<TreeNode> queue=new LinkedList<>();

        queue.offer(left);
        queue.offer(right);
        while(!queue.isEmpty()){
            TreeNode u = queue.poll();
            TreeNode v = queue.poll();

            if(u==null && v==null){
                continue;
            }else if(u==null || v==null){
                return false;
            }else if(u.val!=v.val){
                return false;
            }

            queue.offer(u.left);
            queue.offer(v.right);
            queue.offer(u.right);
            queue.offer(v.left);

        }
        return true;
    }




    public boolean judgeRecusive(TreeNode left, TreeNode right) {

        if (left == null && right == null) {
            return true;
        } else if (left == null || right == null) {
            return false;
        }

        return left.val == right.val && judgeRecusive(left.left, right.right) && judgeRecusive(left.right, right.left);
    }


}
